package com.yun.algorithmproblem.leetcode;

import java.util.*;

public class Leetcode406 {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, (a, b) -> {
            if (a[0] != b[0]) {
                return b[0]-a[0];
            }
            return a[1]-b[1];
        });
        List<int[]> list=new LinkedList<>();
        for (int[] person : people) {
            if(person[1]>=list.size()){
                list.add(person);
            }else {
                list.add(person[1],person);
            }
        }
        return list.toArray(new int[list.size()][]);
    }

    public static void main(String[] args) {
        int[][] people={{7,0},{7,1},{5,0}};
        Leetcode406 obj=new Leetcode406();
        obj.reconstructQueue(people);
    }
}
